use std::ops::Deref;

// Sometimes we want to emulate the following common pattern from OO languages
// such as Java:
//
// class Foo {
//     void m() { ... }
// }
//
// class Bar extends Foo {}
//
// public static void main(String[] args) {
//     Bar b = new Bar();
//     b.m();
// }
//
// We can use the deref polymorphism anti-pattern to do so in Rust.

struct Foo {}

impl Foo {
    fn m(&self) {
        println!("Foo's m function called");
    }
}

struct Bar {
    f: Foo,
}

impl Deref for Bar {
    type Target = Foo;

    fn deref(&self) -> &Foo {
        &self.f
    }
}

fn main() {
    let b = Bar { f: Foo {} };
    b.m();
}
